package com.jyw.web.controller.system;

import com.jyw.common.annotation.Log;
import com.jyw.common.core.controller.BaseController;
import com.jyw.common.core.domain.CommonResult;
import com.jyw.common.core.page.TableDataInfo;
import com.jyw.common.enums.BusinessType;
import com.jyw.system.domain.SysUserTeam;
import com.jyw.system.domain.dto.UserTeamAddDto;
import com.jyw.system.domain.dto.UserTeamLeaderEditDto;
import com.jyw.system.domain.dto.UserTeamPageDto;
import com.jyw.system.domain.vo.UserTeamPageVo;
import com.jyw.system.service.ISysUserTeamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 小组管理Controller
 * 
 * @author system
 * @date 2023-08-07
 */
@RestController
@RequestMapping("/system/user/team")
@Api(tags = "用户小组管理")
public class SysUserTeamController extends BaseController
{
    @Autowired
    private ISysUserTeamService sysUserTeamService;

    /**
     * 查询小组管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:user:team:list')")
    @GetMapping("/list")
    @ApiOperation("用户小组列表")
    public TableDataInfo<UserTeamPageVo> list(UserTeamPageDto userTeamPageVo)
    {
        startPage();
        List<UserTeamPageVo> list = sysUserTeamService.selectSysUserTeamPage(userTeamPageVo);
        return getDataTable(list);
    }

    /**
     * 新增用户小组管理
     */
    @PreAuthorize("@ss.hasPermi('system:user:team:add')")
    @Log(title = "用户小组管理", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增用户小组")
    public CommonResult add(@RequestBody UserTeamAddDto userTeamAddDto)
    {
        sysUserTeamService.addSysUsetTeam(userTeamAddDto);
        return CommonResult.success();
    }

    /**
     * 修改小组管理
     */
    @PreAuthorize("@ss.hasPermi('system:team:edit')")
    @Log(title = "小组管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改用户小组")
    public CommonResult edit(@RequestBody SysUserTeam sysUserTeam)
    {
        return CommonResult.success(sysUserTeamService.updateSysUserTeam(sysUserTeam));
    }

    /**
     * 删除小组管理
     */
    @PreAuthorize("@ss.hasPermi('system:user:team:remove')")
    @Log(title = "用户小组管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除用户小组")
    public CommonResult remove(@PathVariable Long[] ids)
    {
        return CommonResult.success(sysUserTeamService.deleteSysUserTeamByIds(ids));
    }

    /**
     * 组长设置
     */
    @PreAuthorize("@ss.hasPermi('system:user:team:edit')")
    @Log(title = "用户小组管理", businessType = BusinessType.UPDATE)
    @PutMapping("leader")
    @ApiOperation("组长设置")
    public CommonResult editLeader(@RequestBody UserTeamLeaderEditDto leaderEditDto)
    {
        SysUserTeam userTeam = leaderEditDto.buildUserTeam();
        return CommonResult.success(sysUserTeamService.updateSysUserTeam(userTeam));
    }
}
